//
//  IconPickerViewController.swift
//  Todo-Lists
//
//  Created by 吴翰林 on 2019/10/10.
//  Copyright © 2019 吴翰林. All rights reserved.
//

import UIKit

protocol IconPickerViewControllerDelegate:class {
    func iconPicker(_ picker:IconPickerViewController, didPick iconName:String)
}

class IconPickerViewController: UITableViewController {
    weak var delegate:IconPickerViewControllerDelegate?
    
    let icons = ["No Icon",
                 "Appointments",
                 "Birthdays",
                 "Chores",
                 "Drinks",
                 "Folder",
                 "Groceries",
                 "Inbox",
                 "Photo",
                 "Trips"
    ]
    let iconNames =  ["不显示图标",
                      "预约",
                      "生日",
                      "家务",
                      "酒宴",
                      "文件",
                      "杂物",
                      "收件箱",
                      "照片",
                      "出行"
    ]
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

       
    }
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return icons.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "IconCell", for: indexPath)
        
        cell.textLabel!.text = iconNames[indexPath.row]
        cell.imageView!.image = UIImage(named: icons[indexPath.row])
        
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let delegate = delegate {
            let iconName = icons[indexPath.row]
            delegate.iconPicker(self, didPick: iconName)
        }
    }

}
